import { request } from "@/utils/request";

/**
 * 注册
 * @param user
 * @returns
 */
export const register = (user: any) => {
  return request.post("/user/register", user);
};

/**
 * 登录
 * @param user
 * @returns
 */
export const login = (user: any) => {
  return request.post("/user/login", user);
};

/**
 * 上传图片
 * @param data
 * @returns
 */
export const uploadavatar = (data: FormData) => {
  return request.post(`/upload/uploadpic`, data);
};

/**
 * 获取当前用户收藏的文章的id
 * @param id 文章id
 * @returns
 */
export const getcollectidarrapi = (id: number) => {
  return request.get(`/user/getallcollectessayid/${id}`);
};

/**
 * 获取所有用户信息
 * @returns
 */
export const getallusersapi = () => {
  return request.get("/user/getallusers");
};

/**
 * 获取用户成就
 * @param id
 * @returns
 */
export const accomplishapi = (id: number) => {
  return request.get(`/user/accomplish/${id}`);
};

/**
 * 更新用户数据
 * @param id
 * @param username
 * @param avatar
 * @param sex
 * @param introduction
 * @param birthday
 * @returns
 */
export const updateuserapi = (
  id: number,
  username: string,
  avatar: string,
  sex: number,
  introduction: string,
  birthday: string
) => {
  return request.patch(`/user/updateuser/${id}`, {
    username,
    avatar,
    sex,
    introduction,
    birthday,
  });
};

/**
 * 根据用户id重新获取用户信息
 * @param id
 * @returns
 */
export const getoneuserapi = (id: number) => {
  return request.get(`/user/getoneuser/${id}`);
};

/**
 * 根据giteeid获取用户信息
 * @param id
 * @returns
 */
export const bygiteeapi = (id: number) => {
  return request.get(`/user/bygitee/${id}`);
};
